var limit=10000;

var getReverse = function(a) {
    var reverse=0, tmp=a;
    do{
        reverse = reverse*10 + tmp%10;
        tmp = (tmp-tmp%10)/10
    } while(tmp>0);
    return reverse;
};

var isPalindromic = function(a) {
    var hash=[], tmp=a;
    do{
        hash.push(tmp%10);
        tmp = (tmp-tmp%10)/10;
    }while(tmp>0);
    for(var i=0; i<hash.length; i++) {
        if(hash[i] != hash[hash.length-i-1]) return false;
    }
    return true;
};

var count=0;

for(var i=0; i<=10000; i++) {
    var tmp=i;
    for(var j=1; j<=100; j++) {
        var sum=tmp+getReverse(tmp);
        if(isPalindromic(sum)) {
            //print(sum);
            break;
        }
        tmp=sum; 
    }
    if(j>=51) {
        count++;
        //print("Find..." + i);
    }
}

print("count=" + count);
